import { map } from 'rxjs';
import { Transform } from 'class-transformer';
import {
  ArrayMinSize,
  IsArray,
  IsEmail,
  IsMobilePhone,
  IsNumber,
  IsOptional,
  IsString,
} from 'class-validator';

export class CreateUserDto {
  @IsString()
  username: string;

  @IsString()
  nickname: string;

  @Transform(({ value }) => Number(value))
  @IsNumber()
  deptId: number;

  @Transform(({ value }) => Number(value) || 1) // 默认值为1
  @IsOptional()
  @IsNumber()
  gender?: number;

  @Transform(({ value }) => value.map((item) => String(item)))
  @IsArray()
  @ArrayMinSize(1) // 最小长度为1
  roleIds: string[];

  @IsMobilePhone()
  @IsOptional()
  mobile?: string;

  @IsEmail()
  @IsOptional()
  email?: string;

  @Transform(({ value }) => Number(value))
  @IsNumber()
  @IsOptional()
  status?: 1;

  [key: string]: any; // 其他属性
}
